package com.lib.application;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.StringWriter;

/**
 * Created by duqingxiang on 17/5/23.
 */
@Service
public class TemplateService {

    @Autowired
    Configuration configuration;

    public String getTemplateContent(Object dto , String template){
        try {
            Template tmp = configuration.getTemplate(template);

            StringWriter writer = new StringWriter();
            tmp.process(dto,writer);
            return writer.toString();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
